package com.sk.bilibili.adapter.pager.search;

import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;

import com.sk.bilibili.adapter.pager.BaseFragmentAdapter;
import com.sk.bilibili.bean.Them;
import com.sk.bilibili.view.fragment.search.BaseSearchFragment;
import com.sk.bilibili.view.fragment.search.LiveFragment;
import com.sk.bilibili.view.fragment.search.MemberFragment;
import com.sk.bilibili.view.fragment.search.ThemFragment;
import com.sk.bilibili.view.fragment.search.VideoSetFragment;

public class SearchFragmentAdapter extends BaseFragmentAdapter {

    public SearchFragmentAdapter(@NonNull FragmentManager fm) {
        super(fm);
        initData();
    }

    private String[] defTitles="综合,番剧,直播,用户,国创".split(",");
    private String[] titles="综合,番剧,直播,用户,国创".split(",");

    @Override
    protected String[] getTitles() {
        return titles;
    }

    public void setNum(int pos,int num){
        if(num>99){
            titles[pos]=String.format("%s(99+)",defTitles[pos]);
        }else if(num>0){
            titles[pos]=String.format("%s(%d)",defTitles[pos],num);
        }else {
            titles[pos]=defTitles[pos];
        }
        notifyDataSetChanged();
    }

    private BaseSearchFragment[] fragments;

    @Override
    protected Fragment[] getFragments() {
        fragments=new BaseSearchFragment[5];
        fragments[0]=new VideoSetFragment(this,0);
        fragments[1]=new ThemFragment(this,1,2);
        fragments[2]=new LiveFragment(this,2);
        fragments[3]=new MemberFragment(this,3);
        fragments[4]=new ThemFragment(this,4,3);
        return fragments;
    }

    private String keyword;

    public void setKeyword(String keyword) {
        this.keyword = keyword;//只触发显示的更新
        for (BaseSearchFragment fragment:fragments){
            if(fragment.isVisible())fragment.onRefresh();
        }
    }

    public String getKeyword() {
        return keyword;
    }

}